package main

import (
	"fmt"
	"gitee.com/laofa1/play/k_conf_mng/kconf_backend/models"
	"golang.org/x/crypto/ssh/terminal"
	"os"
)

func main() {
	argsAll := os.Args
	if length := len(argsAll); length != 3 {
		fmt.Println("usage: cmd loginName userName")
		return
	}

	loginName := argsAll[1]
	userName := argsAll[2]

	fmt.Printf("password:")
	password1, err := terminal.ReadPassword(0)
	if err != nil {
		fmt.Println("error password input")
		os.Exit(1)
	}
	if string(password1) == "" {
		fmt.Println("password is blank")
		os.Exit(1)
	}

	fmt.Println("")
	fmt.Printf("password again:")
	password2, err := terminal.ReadPassword(0)
	if err != nil {
		fmt.Println("")
		fmt.Println("error password input")
		os.Exit(1)
	}
	if string(password1) != string(password2) {
		fmt.Println("")
		fmt.Println("inputed password not same")
		os.Exit(1)
	}

	if err := models.CreateAdmin(loginName, userName, string(password2)); err != nil {
		fmt.Println("")
		fmt.Print(err)
		os.Exit(1)
	}
	fmt.Println("")
	fmt.Println("Create admin user successfully!")
}

